/* eslint-disable prettier/prettier */
<template>
  <div>
    <topHeader> </topHeader>
    <div class="innercontent">
      <!-- <el-button @click="addBanner" :plain="true">插入产品</el-button>
      <el-button @click="getBanner">查询产品简单</el-button> -->

      <!-- <h1>首页banner</h1>
<div class="divBox">
<p>kjsdjdskdsdsd</p>

</div> -->

      <div style="padding-bottom:20px;">
        <el-button-group style="margin-right:20px;">
          <el-button @click="addBanner" type="primary">添加词条</el-button>
        </el-button-group>

        <el-button-group>
          <el-button style="margin-right:10px;" @click="setupExport">
            导出设置
          </el-button>

          <el-button @click="exportAndroid" :loading="false">
            导出到android
          </el-button>

          <el-button @click="exportIOS">
            导出到iOS
          </el-button>
        </el-button-group>

        <!-- <el-button-group style="margin-right:20px;margin-left:20px;">
          <el-button @click="userManager" type="primary">用户管理</el-button>
        </el-button-group> -->
        <!-- <el-button style="position:absolute; left:40px;" type="primary">添 加</el-button> -->
      </div>
      <!-- 数据列表 -->
      <el-table :data="listdatas" style="width: 100%;" id="customeltable" :default-sort = "{prop: 'zhs'}">
        <el-table-column type="index" width="60"> </el-table-column>

        <el-table-column
          label="词条key"
          property="langkey"
          style="color: blue;"
          width="200"
          sortable
        >
        </el-table-column>

        <!-- <el-table-column property="platform" label="平台"> </el-table-column>

        <el-table-column property="remark" label="描述"> </el-table-column> -->

        <el-table-column property="zhs" label="简体中文" sortable> </el-table-column>

        <el-table-column property="en" label="英文" sortable> </el-table-column>

        <el-table-column label="编辑人" width="100" align="center">
          <template slot-scope="scope">
            <el-tag>{{ getEditUser(scope.row) }}</el-tag>
          </template>
        </el-table-column>

        <el-table-column
          property="createDate"
          label="创建日期"
          align="center"
          width="160"
          sortable
        >
        </el-table-column>

        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button size="small" @click="editSpecs(scope.$index, scope.row)"
              >编辑</el-button
            >

            <!-- <el-button
              size="small"
              @click="moveIsUp(scope.$index, scope.row, true)"
              >上移</el-button
            >
            <el-button
              size="small"
              @click="moveIsUp(scope.$index, scope.row, false)"
              >下移</el-button
            > -->
            <el-button
              size="small"
              type="danger"
              @click="deleteSpecs(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="Pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          :total="itemCount"
        >
        </el-pagination>
      </div>

      <!-- 添加,修改 语言项目 -->
      <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogFormVisible"
        :close-on-click-modal="false"
        :before-close="beforeCloseDialog"
        width="80%"
      >
        <div style="height:550px;overflow:scroll;" ref="theFormDiv">
          <!-- 平台选择 -->

          <el-form
            :model="selectedData"
            :rules="rules"
            label-width="90px"
            ref="theForm"
          >
            <el-form-item label="词条平台:">
              <div>
                <el-radio-group v-model="selectItemPlatformTitle">
                  <el-radio-button label="all"></el-radio-button>
                  <el-radio-button label="iOS"></el-radio-button>
                  <el-radio-button label="android"></el-radio-button>
                  <el-radio-button label="web"></el-radio-button>
                </el-radio-group>
              </div>
            </el-form-item>

            <!-- key -->
            <el-form-item label="词条key:" prop="langkey">
              <el-input
                v-model="selectedData.langkey"
                placeholder="该值唯一,不能输入重复的key"
              ></el-input>
            </el-form-item>

            <el-form-item label="描述:" prop="remark">
              <el-input v-model="selectedData.remark" placeholder=""></el-input>
            </el-form-item>

            <el-row :gutter="20">
              <el-col :span="12">
                <!-- 简体 -->
                <el-form-item
                  :label="langInfo.zhs.name"
                  :prop="langInfo.zhs.indef"
                >
                  <el-input v-model="selectedData.zhs"></el-input>
                </el-form-item>

                <!-- 繁体中文 -->
                <el-form-item
                  :label="langInfo.zht.name"
                  :prop="langInfo.zht.indef"
                >
                  <el-input v-model="selectedData.zht"></el-input>
                </el-form-item>

                <!-- 英语 -->
                <el-form-item
                  :label="langInfo.en.name"
                  :prop="langInfo.en.indef"
                >
                  <el-input v-model="selectedData.en"></el-input>
                </el-form-item>

                <!-- 德语 -->
                <el-form-item
                  :label="langInfo.de.name"
                  :prop="langInfo.de.indef"
                >
                  <el-input v-model="selectedData.de"></el-input>
                </el-form-item>

                <!-- 日语 -->
                <el-form-item
                  :label="langInfo.ja.name"
                  :prop="langInfo.ja.indef"
                >
                  <el-input v-model="selectedData.ja"></el-input>
                </el-form-item>

                 <!-- 韩语 -->
                <el-form-item
                  :label="langInfo.ko.name"
                  :prop="langInfo.ko.indef"
                >
                  <el-input v-model="selectedData.ko"></el-input>
                </el-form-item>

                <!-- 乌克兰 -->
                <el-form-item
                  :label="langInfo.uk.name"
                  :prop="langInfo.uk.indef"
                >
                  <el-input v-model="selectedData.uk"></el-input>
                </el-form-item>

                <!-- 西班牙 -->
                <el-form-item
                  :label="langInfo.es.name"
                  :prop="langInfo.es.indef"
                >
                  <el-input v-model="selectedData.es"></el-input>
                </el-form-item>

                <!-- 意大利  -->
                <el-form-item
                  :label="langInfo.it.name"
                  :prop="langInfo.it.indef"
                >
                  <el-input v-model="selectedData.it"></el-input>
                </el-form-item>

                <!-- 波兰 -->
                <el-form-item
                  :label="langInfo.pl.name"
                  :prop="langInfo.pl.indef"
                >
                  <el-input v-model="selectedData.pl"></el-input>
                </el-form-item>

                <!-- 俄语 -->
                <el-form-item
                  :label="langInfo.ru.name"
                  :prop="langInfo.ru.indef"
                >
                  <el-input v-model="selectedData.ru"></el-input>
                </el-form-item>

                <!-- 法语 -->
                <el-form-item
                  :label="langInfo.fr.name"
                  :prop="langInfo.fr.indef"
                >
                  <el-input v-model="selectedData.fr"></el-input>
                </el-form-item>

                <!-- 印度尼西亚 -->
                <el-form-item
                  :label="langInfo.idn.name"
                  :prop="langInfo.idn.indef"
                >
                  <el-input v-model="selectedData.idn"></el-input>
                </el-form-item>

                <!-- 葡萄牙 -->
                <el-form-item
                  :label="langInfo.pt.name"
                  :prop="langInfo.pt.indef"
                >
                  <el-input v-model="selectedData.pt"></el-input>
                </el-form-item>

                <!-- 越南 -->
                <el-form-item
                  :label="langInfo.vi.name"
                  :prop="langInfo.vi.indef"
                >
                  <el-input v-model="selectedData.vi"></el-input>
                </el-form-item>

                <!-- 希伯来语 -->
                <el-form-item
                  :label="langInfo.iw.name"
                  :prop="langInfo.iw.indef"
                >
                  <el-input v-model="selectedData.iw"></el-input>
                </el-form-item>

                <!-- 阿拉伯语 -->
                <el-form-item
                  :label="langInfo.ar.name"
                  :prop="langInfo.ar.indef"
                >
                  <el-input v-model="selectedData.ar"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <!-- 高棉语 -->
                <el-form-item
                  :label="langInfo.km.name"
                  :prop="langInfo.km.indef"
                >
                  <el-input v-model="selectedData.km"></el-input>
                </el-form-item>

                <!--印尼 -->
                <el-form-item
                  :label="langInfo.in.name"
                  :prop="langInfo.in.indef"
                >
                  <el-input v-model="selectedData.in"></el-input>
                </el-form-item>

                <!-- 捷克 -->
                <el-form-item
                  :label="langInfo.cs.name"
                  :prop="langInfo.cs.indef"
                >
                  <el-input v-model="selectedData.cs"></el-input>
                </el-form-item>

                <!-- 阿塞拜疆语  -->
                <el-form-item
                  :label="langInfo.az.name"
                  :prop="langInfo.az.indef"
                >
                  <el-input v-model="selectedData.az"></el-input>
                </el-form-item>

                <!-- 荷兰 -->
                <el-form-item
                  :label="langInfo.nl.name"
                  :prop="langInfo.nl.indef"
                >
                  <el-input v-model="selectedData.nl"></el-input>
                </el-form-item>

                <!-- 老挝 -->
                <el-form-item
                  :label="langInfo.lo.name"
                  :prop="langInfo.lo.indef"
                >
                  <el-input v-model="selectedData.lo"></el-input>
                </el-form-item>

                <!-- 土耳其  -->
                <el-form-item
                  :label="langInfo.tr.name"
                  :prop="langInfo.tr.indef"
                >
                  <el-input v-model="selectedData.tr"></el-input>
                </el-form-item>

                <!-- 泰语 -->
                <el-form-item
                  :label="langInfo.th.name"
                  :prop="langInfo.th.indef"
                >
                  <el-input v-model="selectedData.th"></el-input>
                </el-form-item>

                <!-- 孟加拉  -->
                <el-form-item
                  :label="langInfo.bn.name"
                  :prop="langInfo.bn.indef"
                >
                  <el-input v-model="selectedData.bn"></el-input>
                </el-form-item>

                <!-- 丹麦  -->
                <el-form-item
                  :label="langInfo.da.name"
                  :prop="langInfo.da.indef"
                >
                  <el-input v-model="selectedData.da"></el-input>
                </el-form-item>

                <!-- 波斯语 -->
                <el-form-item
                  :label="langInfo.fa.name"
                  :prop="langInfo.fa.indef"
                >
                  <el-input v-model="selectedData.fa"></el-input>
                </el-form-item>

                <!-- 印地语 -->
                <el-form-item
                  :label="langInfo.hi.name"
                  :prop="langInfo.hi.indef"
                >
                  <el-input v-model="selectedData.hi"></el-input>
                </el-form-item>

                <!-- 格鲁吉亚 -->
                <el-form-item
                  :label="langInfo.ka.name"
                  :prop="langInfo.ka.indef"
                >
                  <el-input v-model="selectedData.ka"></el-input>
                </el-form-item>

                <!-- 塞尔维亚 -->
                <el-form-item
                  :label="langInfo.sr.name"
                  :prop="langInfo.sr.indef"
                >
                  <el-input v-model="selectedData.sr"></el-input>
                </el-form-item>

                <!-- 蒙古 -->
                <el-form-item
                  :label="langInfo.mn.name"
                  :prop="langInfo.mn.indef"
                >
                  <el-input v-model="selectedData.mn"></el-input>
                </el-form-item>

                <!-- 瑞典 -->
                <el-form-item
                  :label="langInfo.sv.name"
                  :prop="langInfo.sv.indef"
                >
                  <el-input v-model="selectedData.sv"></el-input>
                </el-form-item>

                <!--马其顿  -->
                <el-form-item
                  :label="langInfo.mk.name"
                  :prop="langInfo.mk.indef"
                >
                  <el-input v-model="selectedData.mk"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancelEditBanner">取 消</el-button>
          <el-button type="primary" @click="insertOrUpdate">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 导出设置 -->
      <exportSetting ref="exportSetting"></exportSetting>
    </div>
  </div>
</template>

<script>
import {
  langItemCreate,
  langItemUpdate,
  langItemDelete,
  langItemList,
  generalSort,
  exportLangItems
} from "../api/getData";

import topHeader from "../views/headerTop";
import * as commonConst from "../common/commonConst";
import exportSetting from "@/components/exportSetting";
import { getUrlKey } from "@/common/mUtils";
import { getNowFormatDate } from "@/common/DateUtils";
export default {
  components: {
    topHeader,
    exportSetting
  },

  //-----数据--------
  data() {
    return {
      baseUploadUrl: "",
      listdatas: [],
      curProjID: "", //当前projID
      dialogTitle: "添加词条",
      dialogFormVisible: false, //词条录入修改
      dialogExportVisible: false, //导出设置
      selectedData: {},
      currentSelectIndex: -1, //当前selectedData 的 index
      currentPage: 1,
      totalpage: 1,
      itemCount: 0,
      pageSize: 500, //commonConst.basePagesize,
      rules: {
        langkey: [
          { required: true, message: "请输入名称", trigger: "blur" },
          { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" }
        ]
      },
      langInfo: {
        zhs: { name: "简体中文", indef: "zhs" },
        zht: { name: "繁体中文", indef: "zht" },
        en: { name: "英语", indef: "en" },
        de: { name: "德语", indef: "de" },
        ja: { name: "日语", indef: "ja" },
        uk: { name: "乌克兰", indef: "uk" },
        es: { name: "西班牙", indef: "es" },
        it: { name: "意大利", indef: "it" },
        pl: { name: "波兰", indef: "pl" },
        ko: { name: "韩语", indef: "ko" },
        ru: { name: "俄语", indef: "ru" },
        fr: { name: "法语", indef: "fr" },
        idn: { name: "印度尼西亚", indef: "idn" },
        pt: { name: "葡萄牙", indef: "pt" },
        vi: { name: "越南", indef: "vi" },
        iw: { name: "希伯来语", indef: "iw" },
        ar: { name: "阿拉伯语", indef: "ar" },
        km: { name: "高棉语", indef: "km" },
        in: { name: "印尼", indef: "in" },
        cs: { name: "捷克", indef: "cs" },
        az: { name: "阿塞拜疆语", indef: "az" },
        nl: { name: "荷兰", indef: "nl" },
        lo: { name: "老挝", indef: "lo" },
        tr: { name: "土耳其", indef: "tr" },
        th: { name: "泰语", indef: "th" },
        bn: { name: "孟加拉", indef: "bn" },
        da: { name: "丹麦", indef: "da" },
        fa: { name: "波斯语", indef: "fa" },
        hi: { name: "印地语", indef: "hi" },
        ka: { name: "格鲁吉亚", indef: "ka" },
        sr: { name: "塞尔维亚", indef: "sr" },
        mn: { name: "蒙古", indef: "mn" },
        sv: { name: "瑞典", indef: "sv" },
        mk: { name: "马其顿", indef: "mk" }
      },

      //当前词条对应的平台,默认通用
      selectItemPlatformTitle: "all",

      //当前平台的列表,默认通用
      currentListPlatformTitle: "all"
    };
  },

  created() {
    //获取产品id
    let pid = getUrlKey("projID");
    if (typeof pid == "undefined" || pid == null || pid == "") {
      this.curProjID = "";
    } else {
      this.curProjID = pid;
    }
  },

  mounted() {
    setTimeout(async () => {
      this.requestDatas();
    }, 20);
  },

  computed: {
    // ...mapState(['adminInfo']),
  },
  methods: {
    //-------------------------业务逻辑---------------------------
    //还原参数
    resetParam() {
      this.dialogTitle = "添加词条";
      this.dialogFormVisible = false; //词条录入修改
      this.dialogExportVisible = false; //导出设置
      this.selectedData = {};
      this.currentSelectIndex = -1; //当前selectedData 的 index
      this.currentPage = 1;
      this.totalpage = 1;
      this.itemCount = 0;
      this.pageSize = 500; //commonConst.basePagesize,
    },

    //获取编辑人--------
    getEditUser(item) {
      //return "Admin";
      //return "editUser" in item ? item.editUser : "Admin";
      // return typeof item.editUser == "undefined" || item.editUser == ""
      //   ? "Admin"
      //   : item.editUser;
      //return item.editUser == undefined ? item.editUser : "Admin";

      //  item 如果没有editUser的值会导致读取错误 引起 排版错误
      try {
        return typeof item.editUser == "undefined" || item.editUser == ""
          ? "Admin"
          : item.editUser;
      } catch (error) {
        return "AD";
      }
    },

    //清空选中数据源--------
    emptySelectData() {
      this.selectedData = {}; //;
      // console.log(index, obj);
    },
    //清空表单-----------
    delayResetFields(isDelay) {
      if (!this.$refs["theForm"]) {
        return;
      }

      if (isDelay) {
        //由于首次出现还没挂载,需要延时执行
        setTimeout(() => {
          this.$refs["theForm"].resetFields();
        }, 250);
      } else {
        this.$refs["theForm"].resetFields();
      }
    },

    //获取信息----------
    async requestDatas() {
      try {
        let para = {
          page: this.currentPage,
          pagesize: this.pageSize,
          projID: this.curProjID
        };
        const resp = await langItemList(para);
        if (resp.errorCode == 0) {
          this.listdatas = resp.data == null ? [] : resp.data;
          this.itemCount = resp.itemCount;
        } else {
          this.$message.error("获取失败");
        }
      } catch (err) {
        this.$message({
          type: "error",
          message: commonConst.error_connect_reload
        });
      }
    },

    //编辑--------
    editSpecs(index, obj) {
      this.currentSelectIndex = index;
      this.dialogTitle = "修改词条";
      this.selectedData = JSON.parse(JSON.stringify(obj)); //Object.assign({},obj) Object.assign会跳过值为null的对象
      this.dialogFormVisible = true;
      this.selectItemPlatformTitle = obj.platform;
      if (this.$refs["theFormDiv"]) {
        setTimeout(() => {
          this.$refs["theFormDiv"].scrollTop = 0; //每次出现滚到最顶部
        }, 20);
      }

      // console.log(index, obj);
    },

    //删除---------
    deleteSpecs(index, obj) {
      // this.$message.error("上传图片失败！");
      this.currentSelectIndex = index;
      this.$confirm("是否要删除该项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          // this.$message({
          //   type: 'success',
          //   message: '删除成功!'
          // });
          try {
            const resp = await langItemDelete(obj);

            if (resp.errorCode == 0) {
              //删除元素
              this.listdatas.splice(index, 1);
              this.itemCount = this.itemCount - 1;
            } else {
              this.$message({
                type: "error",
                message: "删除失败"
              });
            }
          } catch (err) {
            this.$message({
              type: "error",
              message: "连接超时"
            });
          }
        })
        .catch(() => {
          // this.$message({
          //   type: 'info',
          //   message: '已取消删除'
          // });
        });
    }, //

    //更新---------
    insertOrUpdate() {
      this.$refs["theForm"].validate(async valid => {
        if (valid) {
          //语言平台修改
          this.selectedData.platform = this.selectItemPlatformTitle;

          //插入
          if (this.selectedData.id == null) {
            //当前项目ID
            this.selectedData.projID = this.curProjID;

            //console.log("提交:", this.selectedData);
            try {
              const res = await langItemCreate(this.selectedData);

              if (res.errorCode == 0) {
                let obj = res.data;
                //console.log("返回:", obj);
                // this.listdatas.push(obj); //加在最后
                if (this.listdatas.length > 0) {
                  this.listdatas.unshift(obj); //加在第一个
                } else {
                  this.listdatas.push(obj); //加在最后
                }

                this.$message.success("添加成功");
                this.dialogFormVisible = false;
                this.itemCount = this.itemCount + 1;
              } else {
                this.$message.error("添加失败");
              }
            } catch (err) {
              this.$message({
                type: "error",
                message: err
              });
              console.log("获取失败", err);
            }
          } else {
            //更新
            try {
              // console.log("上传的数据:", this.selectedData);

              //修改编辑时间
              this.selectedData.createDate = getNowFormatDate();


              //防止某些词条没有projID
              if(this.selectedData.projID == undefined || this.selectedData.projID == ''){
                this.selectedData.projID = this.curProjID
              }


              const res = await langItemUpdate(this.selectedData);

              if (res.errorCode == 0) {
                this.listdatas.splice(
                  this.currentSelectIndex,
                  1,
                  this.selectedData
                ); //这样才会触发 对象里面的get/set
                //this.listdatas[this.currentSelectIndex] = Object.assign({},this.selectedData) //这样不会触发get/set
                //this.requestDatas();
                console.log("currentSelectIndex:", this.currentSelectIndex);
                // this.requestDatas()

                this.dialogFormVisible = false;
              } else {
                this.$message.error("添加失败");
              }
            } catch (err) {
              this.$message({
                type: "error",
                message: err
              });
              console.log("获取失败", err);
            }
          }
        } else {
          console.log("输入校验失败");
        }
      });
    },

    //上移下移--------
    async moveIsUp(index, obj, isUp) {
      var targetIndex = 0;

      //上移
      if (isUp) {
        if (index == 0) {
          alert("已经置顶");
          return;
        }

        targetIndex = index - 1;
      } else {
        //下移
        if (index == this.listdatas.length - 1) {
          alert("已经到底");
          return;
        }

        targetIndex = index + 1;
      }

      var targetObj = this.listdatas[targetIndex];

      try {
        var data = {
          id1: obj.id,
          sort1: obj.sort,
          id2: targetObj.id,
          sort2: targetObj.sort,
          col: "homeBanner"
        };
        const resp = await generalSort(data);
        if (resp.errorCode == 0) {
          this.$message.success("设置排序成功");
          obj.sort = data.sort2;
          targetObj.sort = data.sort1;
          this.$set(this.listdatas, targetIndex, obj);
          this.$set(this.listdatas, index, targetObj);
        } else {
          this.$message.error("获取失败");
        }
      } catch (err) {
        this.$message.error(commonConst.error_connect_reload);
      }
    },

    //取消编辑---------
    cancelEditBanner() {
      this.dialogFormVisible = false;
    },

    //点击添加按钮--------
    addBanner() {
      this.delayResetFields(false);

      this.dialogTitle = "添加词条";
      this.emptySelectData();
      this.dialogFormVisible = true;
      this.selectItemPlatformTitle = "all";
    },

    //点击用户管理-------
    userManager() {
      this.$router.push("userManager");
    },

    //点击用户管理-------
    setupExport() {
      this.$refs["exportSetting"].dialogExportVisible = true;
    },

    //导出到Android--------
    exportAndroid() {
      let items = this.$store.state.androidExportLangs;
      let selectItems = [];
      for (let v of items) {
        if (v.check == true) {
          selectItems.push(v.indef);
        }
      }

      if (selectItems.length == 0) {
        this.$message({
          type: "error",
          message: "请勾选android平台需要导出的语言"
        });
        return;
      }

      this.exportAction(selectItems, "android");

      //window.location.href = commonConst.baseUrl + "/api/exportLang/android";
    },

    //导出到iOS--------
    exportIOS() {
      // window.open(
      //   "http://localhost:8083/api/exportLangItems/iOS/5c5aa86d2cfbd48d997c6e53"
      // );
      // return;
      // console.log(this.$store.state.iOSExportUseZhtKey);

      let items = this.$store.state.iOSExportLangs;
      let selectItems = [];
      for (let v of items) {
        if (v.check == true) {
          selectItems.push(v.indef);
        }
      }

      // 导出设置判断
      if (selectItems.length == 0) {
        this.$message({
          type: "error",
          message: "请勾选iOS平台需要导出的语言"
        });
        return;
      }

      this.exportAction(selectItems, "iOS");

      //window.location.href = commonConst.baseUrl + "/api/exportLang/iOS";
    },

    async exportAction(selectItems, m_platform) {
      if (this.curProjID.length == 0) {
        this.$message({
          type: "error",
          message: "项目不存在"
        });
        return;
      }

      try {
        var data = {
          langs: selectItems,
          isIOSuseZhKey: this.$store.state.iOSExportUseZhtKey
        };

        const resp = await exportLangItems(m_platform, this.curProjID, data);

        //console.log("导出返回:", resp);
        if (resp.errorCode == 0 && resp.data != null) {
          // this.$message.success("设置排序成功");
          // obj.sort = data.sort2;
          // targetObj.sort = data.sort1;
          // this.$set(this.listdatas, targetIndex, obj);
          // this.$set(this.listdatas, index, targetObj);
          //alert(resp.data);
          //下载压缩包
          window.open(resp.data, "_blank");
          // window.location.href(resp.data);
        } else {
          //this.$message.error("获取失败");
        }
      } catch (err) {
        // console.log("返回err:", err);
        this.$message.error(commonConst.error_export);
      }
    },

    //==========其他组件方法=======
    //dialog组件回调--------
    beforeCloseDialog(done) {
      //真正关闭
      done();

      this.emptySelectData();
      this.delayResetFields(false);
    },

    //上传组件 成功--------
    handleServiceImgScucess(res, file) {
      //console.log("resp:", res);

      if (res.errorCode == 0) {
        this.selectedData.img = res.data[0].url;
        console.log("图片:", this.selectedData.img);
        //this.$message.success("上传图片成功！");
      } else {
        this.$message.error("上传图片失败！");
      }
    },
    //上传组件 失败 , 一般是服务器挂掉或网络不行--------
    handleServiceImgError(res, file) {
      this.$message.error("上传失败,请稍后再试");
    },

    //上传组件 上传前--------
    beforeImgUpload(file) {
      const isRightType =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/gif";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isRightType) {
        this.$message.error("上传图片只能是 JPG/PNG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isRightType && isLt2M;
    },
    //分页组件 回调--------
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    //分页组件 处理当前分页请求 回调--------
    handleCurrentChange(val) {
      this.currentPage = val;
      // console.log(this.currentPage)
      this.requestDatas();
    }
  },
  watch: {
    //监听路由刷新,同一路由,但参数不一样,强制刷新
    $route(to, from) {
      console.log("1234567834567845678");
      // this.$router.go(0);
      let pid = getUrlKey("projID");

      if (typeof pid == "undefined" || pid == null || pid == "") {
        this.curProjID = "";
      } else {
        if (pid == this.curProjID) {
          return;
        }
        this.curProjID = pid;
      }
      this.resetParam();
      this.requestDatas();
    }
  }
};
</script>

<style lang="less" scoped>
@import "../style/mixin.less";
</style>
